package com.ruicar.afs.cloud.manage.revoke.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import com.ruicar.afs.cloud.manage.common.service.ManageCollectCancelService;
import com.ruicar.afs.cloud.manage.revoke.condition.ManageCollectCancelCondition;
import com.ruicar.afs.cloud.manage.revoke.vo.ManageCollectCancelVo;
import com.ruicar.afs.cloud.manage.revoke.vo.ManageRevokeHandleVo;
import com.ruicar.afs.cloud.manage.workflow.processor.ApproveTaskProcessor;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * @author infinity
 * @version 1.0
 * @date 2020/8/7 14:46
 */
@Slf4j
@RestController
@Api("收款撤销")
@RequestMapping("/revokeCollection")
@AllArgsConstructor
public class ManageCollectCancelController {

    private final ManageCollectCancelService manageCollectCancelService;
    private final ApproveTaskProcessor approveTaskProcessor;

    @ApiOperation("获取收款撤销案件信息")
    @PostMapping("/queryManageCollectCancelList")
    public IResponse queryManageCollectCancelList(@RequestBody ManageCollectCancelCondition condition ){
        IPage<ManageRevokeHandleVo>   list=manageCollectCancelService.queryManageCollectCancelList(condition);
        IPage page = list;
        page.setRecords(approveTaskProcessor.handle(page.getRecords()));
        return IResponse.success(page);
    }

    @ApiOperation("获取收款撤销案件信息")
    @PostMapping("/getManageCollectCancel")
    public IResponse getManageCollectCancel(@RequestParam("id") Long id){
       return IResponse.success(manageCollectCancelService.getById(id));
    }
    @ApiOperation("获取收款撤销案件信息")
    @PostMapping("/getManageCollectCancelByCaseNo")
    public IResponse getManageCollectCancelByCaseNo(@RequestParam("caseNo") String  caseNo){
       return IResponse.success(manageCollectCancelService.getManageCollectCancelByCaseNo(caseNo));
    }
    @PostMapping(value = "/revokedStartProcess")
    @ApiOperation(value = "发起流程")
    public IResponse revokedStartProcess(@RequestBody ManageCollectCancelVo vo) {
        return IResponse.success(manageCollectCancelService.revokedStartProcess(vo));
    }
    @PostMapping(value = "/saveCollectCancel")
    @ApiOperation(value = "保存收款撤销")
    @Transactional
    public IResponse saveRevokeSubmitProcess(@RequestBody ManageCollectCancelVo collectCancelVo) {
        return IResponse.success(manageCollectCancelService.saveCollectCancel(collectCancelVo));
    }
    @PostMapping(value = "/revokeSubmitProcess")
    @ApiOperation(value = "提交流程")
    @Transactional
    public IResponse revokeSubmitProcess(@RequestBody ManageCollectCancelVo collectCancelVo) {
        return IResponse.success(manageCollectCancelService.revokeSubmitProcess(collectCancelVo));
    }
    @ApiOperation("获取收款撤销案件信息")
    @PostMapping("/getManageHandleList")
    public IResponse getManageHandleList(@RequestBody ManageCollectCancelCondition condition ){
        return IResponse.success(manageCollectCancelService.getManageHandleList(condition));
    }
    @PostMapping(value = "/agreeValid")
    @ApiOperation(value = "审核通过操作的校验")
    public IResponse<String> agreeValid(@RequestBody ManageCollectCancelVo collectCancelVo) {
        return IResponse.success(manageCollectCancelService.agreeValid(collectCancelVo));
    }
}
